﻿/** 
 * Description:订单明细表DAO
 * Date:2011-7-16
 * Author:Along	
*/
package com.community.shopping.dao;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.community.shopping.domain.OrderItem;
import com.community.shopping.service.logic.Page;

public class OrderItemDao extends HibernateDaoSupport{
	private Log log = LogFactory.getLog(GoodsTypeDao.class);  
	

	public void save(OrderItem orderItem){
		getHibernateTemplate().saveOrUpdate(orderItem);	
		log.debug("-------保存一行orderItem-------");
	}

	public void delete(OrderItem orderItem){		  
		getHibernateTemplate().delete(orderItem);
		log.debug("---------删除一行orderItem-------");
	}


	public List<?> getOrderItem() {  		
	 return getHibernateTemplate().find(" from OrderItem"); 
	 }

	public List<OrderItem> getOrderItem(String sql){
		String finalsql="from OrderItem where "+sql;
		return getHibernateTemplate().find(finalsql);
	}   
	
	public List<?> getGoodsItem(String sql,Page page){
		String finalsql=" from OrderItem where "+sql;
		Query   query   = this.getSession().createQuery(finalsql+" order by orderNo desc"); 
		query.setFirstResult(page.getPageStartRow()>0?page.getPageStartRow()-1:0); 
		query.setMaxResults(page.getPageSize()); 
		if(page.getTotalRowsAmount()==0)
		{
		page.setTotalRowsAmount(getTotalCount(finalsql));
		}
		List   stu   =   query.list(); 
		return stu;
	} 
	
	public int getTotalCount(String sql)
	{
		Query   query   = this.getSession().createQuery("select count(*) "+sql); 
		int i=Integer.parseInt(query.list().get(0).toString());
		return i;
	}
	
	}